package com.compare.util;

import java.util.concurrent.*;

public class ThreadUtils {

    int corePoolSize = 16;    // 核心线程数
    int maxPoolSize = 16;    // 最大线程数
    long keepAliveTime = 3; // 空闲线程存活时间(秒)
    BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(10000); // 工作队列
    ThreadPoolExecutor customThreadPool;
    public ThreadUtils() {
        customThreadPool = new ThreadPoolExecutor(
                corePoolSize,
                maxPoolSize,
                keepAliveTime,
                TimeUnit.SECONDS,
                workQueue,
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy() // 拒绝策略
        );
    }


    public ThreadPoolExecutor getCustomThreadPool() {
        return customThreadPool;
    }
}
